package com.bah.tract.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;
import org.jboss.seam.security.Credentials;

import com.bah.tract.model.Project;

@Name("projectHome")
public class ProjectHome extends EntityHome<Project> {

	@In
	Credentials credentials;

	@Override
	public String persist() {
		Project project = getInstance();
		LOG.info(credentials.getUsername() + " is creating project "
				+ project.getLabel());
		return super.persist();
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Log LOG = LogFactory.getLog(ProjectHome.class);

	public void setProjectId(Long id) {
		setId(id);
	}

	public Long getProjectId() {
		return (Long) getId();
	}

	@Override
	protected Project createInstance() {
		Project project = new Project();
		return project;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
	}

	public boolean isWired() {
		return true;
	}

	public Project getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

}
